function PopupPage() {
	this.eventManager=new EventManager();
	var listenerName=Map.parse(location.search.substr(1), "&", "=").getValue("listener");
	this.listener=opener[listenerName];
	this.parentDocument = opener.document;
	if (Utils.isDefined(listenerName)) this.eventManager.registerListener(this.listener);	
	
	Framework.instance.registerFinalizer(this);	
}

PopupPage.prototype.isParentAlive = function () {
    return Utils.isDefined(opener)&&!opener.closed&&this.parentDocument == opener.document;
}

//Returns data from popup & closes the popup window
PopupPage.prototype.populate = function (data) {
	if (!this.isParentAlive()) {
	    //Do nothing, just close popup
	    window.close();
	    return false;
	}
	
	var eventInfo={"data": data, "target": this, "cancel": false};
	this.eventManager.fireEvent("prepopulate", eventInfo);
	if (eventInfo["cancel"]){
		return; 
	}
	delete eventInfo.cancel;
	this.eventManager.fireEvent("populate", eventInfo);
	window.close();
	return false;
}


PopupPage.prototype.finalize = function() {
    this.parentDocument = null;
    this.eventManager = null;
    this.listener = null;
}

//Deprecated
PopupPage.prototype.prepareData=function (results, convertToMap) {
	if (typeof(convertToMap)=="undefined"){
		convertToMap=true;
	}
	if (typeof(results)=="string"&&convertToMap){
		results=new Map(results);
		results.keys[0]="id";
		results.keys[1]="display.text";
	}
	return results;
}

//Deprecated
PopupPage.prototype.returnResult=function (results, convertToMap) {
    if (!this.isParentAlive()) {
	    //Do nothing, just close popup
	    window.close();
	    return false;
	}

	
	results=this.prepareData(results, convertToMap);

	var eventInfo={"data": results, "target": this, "cancel": false};
	this.eventManager.fireEvent("prepopulate", eventInfo);
	if (eventInfo["cancel"]){
		return; 
	}
	delete eventInfo.cancel;
	this.eventManager.fireEvent("populate", eventInfo);
	window.close();
	return false;
}	
